Skip to content

fix(ttf): name the offending codepoint when no glyph is available#1931

Open
NadeemIqbal wants to merge 1 commit into
DavBfr:masterfrom
NadeemIqbal:fix/issue-1919-missing-glyph-diagnostic
Open

fix(ttf): name the offending codepoint when no glyph is available#1931
NadeemIqbal wants to merge 1 commit into
DavBfr:masterfrom
NadeemIqbal:fix/issue-1919-missing-glyph-diagnostic

Conversation

@NadeemIqbal

Copy link
Copy Markdown

TtfWriter.withChars falls back to glyphsMap.values.first when the requested glyph index isn't in the subset cache. If every glyph has already been consumed (e.g. a font that has no glyph for an Arabic Presentation Form codepoint AND no surrounding chars added other glyphs), that .first call throws the generic Dart-runtime error Bad state: No element, which gives the user zero clue what input triggered it.

Reformulate the fallback as an explicit if/else and, in the truly-empty case, raise a clearer exception that names the offending character and its Unicode codepoint (and the font that lacks it). The non-empty fallback path is preserved bit-for-bit — only the otherwise-untyped runtime crash is replaced.

Closes #1919.

`TtfWriter.withChars` falls back to `glyphsMap.values.first` when the
requested glyph index isn't in the subset cache. If every glyph has
already been consumed (e.g. a font that has no glyph for an Arabic
Presentation Form codepoint AND no surrounding chars added other
glyphs), that `.first` call throws the generic Dart-runtime error
`Bad state: No element`, which gives the user zero clue what input
triggered it.

Reformulate the fallback as an explicit if/else and, in the
truly-empty case, raise a clearer exception that names the offending
character and its Unicode codepoint (and the font that lacks it). The
non-empty fallback path is preserved bit-for-bit — only the
otherwise-untyped runtime crash is replaced.

Closes DavBfr#1919.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When generating a PDF with Arabic text, the library may throw the following exception: Bad state: No element

1 participant